<?php
class Application_Acl_DefaultAcl extends Zend_Acl{
	public function __construct(){
		$this->_initRessources();
		$this->_initRoles();
		$this->_initRights();
		
		Zend_Registry::set('DefaultAcl', $this);
	}
	
	protected function _initRessources(){
		$this->addResource(new Zend_Acl_Resource('default:index'));
		$this->addResource(new Zend_Acl_Resource('default:login'));
		$this->addResource(new Zend_Acl_Resource('default:news'));
		$this->addResource(new Zend_Acl_Resource('default:comment'));
		$this->addResource(new Zend_Acl_Resource('default:error'));
		$this->addResource(new Zend_Acl_Resource('default:register'));
		$this->addResource(new Zend_Acl_Resource('default:mail'));
		$this->addResource(new Zend_Acl_Resource('prof:index'));
		$this->addResource(new Zend_Acl_Resource('prof:qcm'));
		$this->addResource(new Zend_Acl_Resource('prof:quest'));
		$this->addResource(new Zend_Acl_Resource('prof:rep'));
		$this->addResource(new Zend_Acl_Resource('prof:attrib'));
		$this->addResource(new Zend_Acl_Resource('admin:index'));
		$this->addResource(new Zend_Acl_Resource('android:login'));
		$this->addResource(new Zend_Acl_Resource('android:qcm'));
		$this->addResource(new Zend_Acl_Resource('android:*'));
	}
	protected function _initRoles(){
		$guest = new Zend_Acl_Role('guest');
		$etudiant = new Zend_Acl_Role('etudiant');
		$prof = new Zend_Acl_Role('prof');
		$admin = new Zend_Acl_Role('admin');
		
		$this->addRole($guest);
		$this->addRole($etudiant,$guest);
		$this->addRole($prof,$etudiant);
		$this->addRole($admin,$prof);
	}
	protected function _initRights(){
		$this->allow('guest',array(
				'default:index',
				'default:error',
				'default:login',
				'default:register',
				'android:*',
				'default:news'
		));
		$this->allow('guest','default:comment',array('index'));
		$this->allow('etudiant',array('default:mail','default:comment','android:qcm'));
		$this->allow('prof',array('prof:index','prof:qcm','prof:quest','prof:rep','prof:attrib'));
		$this->deny('etudiant','android:login','login');
		$this->deny('etudiant','default:login','login');
		$this->deny('etudiant','default:register');
		$this->allow('admin');
	}
}